﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Validation;

namespace PrismTutorial.DataLayer.ValidationBlock {
    public static class EntityValidator<T> {

        public static Dictionary<string,string> ValidationErrors { get; set; }

        public static bool Validate<T>(T entity) {
            ValidationResults results = Validation.ValidateFromConfiguration<T>(entity);
            if (results.IsValid) {
                return true;
            } else {
                foreach (var error in results) {
                    ValidationErrors.Add(error.Key, error.Message);
                }
                return false;
            }
        }
    }
}
